$OpenBSD: patch-agen5_defLoad_c,v 1.1 2006/12/09 18:28:53 kili Exp $

# Fix use after realloc.

--- agen5/defLoad.c.orig	Sun Sep 24 04:58:59 2006
+++ agen5/defLoad.c	Sun Nov 19 18:30:20 2006
@@ -418,6 +418,7 @@ readDefines( void )
          */
         if (sizeLeft == 0) {
             tScanCtx* p;
+            char *oldPzData;
 
             /*
              *  IF it is a regular file, then we are done
@@ -430,6 +431,7 @@ readDefines( void )
              *  Try to reallocate our input buffer.
              */
             dataSize += (sizeLeft = 0x1000);
+            oldPzData = pBaseCtx->pzData;
             p = (tScanCtx*)AGREALOC( (void*)pBaseCtx,
                                      dataSize+4+sizeof( *pBaseCtx ),
                                      "expanded file buffer" );
@@ -442,7 +444,7 @@ readDefines( void )
             if (p != pBaseCtx) {
                 p->pzScan = \
                 p->pzData = (char*)(p+1);
-                pzData = p->pzData + (pzData - pBaseCtx->pzData);
+                pzData = p->pzData + (pzData - oldPzData);
                 pBaseCtx = p;
             }
         }
